package com.drought.rained.presenter;

import com.drought.rained.BuildConfig;
import com.drought.rained.business.CustomConsumerLJ;
import com.drought.rained.business.ParamsFactoryLJ;
import com.drought.rained.cache.UserInfoLJ;
import com.drought.rained.mvpview.BankCardMvpViewLJ;
import com.drought.rained.response.BindedCardResponseLJ;
import com.drought.rained.response.BlankResponseLJ;
import com.drought.rained.response.PersonalInfoResponseLJ;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import io.reactivex.functions.Consumer;

public class BankCardPresenterLJ extends BasePresenterLJ {
    private BankCardMvpViewLJ mvpView;

    public BankCardPresenterLJ(BankCardMvpViewLJ mvpView) {
        this.mvpView = mvpView;
    }

    public void getBankInfo() {
        Map<String, Object> map = new HashMap<>();
        map.put("userUuid", UserInfoLJ.getShowUuid());
        List<String> steps = new ArrayList<>();
        steps.add("bank_info_code");
        map.put("pageCodes", steps);
        toSubScribe(req.getBindedCardData(UserInfoLJ.getToken(), ParamsFactoryLJ.getCommonParams(map)), new CustomConsumerLJ<BindedCardResponseLJ>() {
            @Override
            public void call(BindedCardResponseLJ bindedCardResponse) {
                mvpView.onGetDataNext(bindedCardResponse);
            }
        }, new Consumer<Throwable>() {
            @Override
            public void accept(Throwable throwable) throws Exception {
                mvpView.onGetDataError(throwable);
            }
        });
    }

    public void saveBankCard(String realName, String bankCode, String bankName, String bankCard) {
        Map<String, Object> formMap = new HashMap<>();
        formMap.put("userUuid", UserInfoLJ.getSaveUuid());
        formMap.put("realName", realName);
        formMap.put("bankCode", bankCode);
        formMap.put("bankName", bankName);
        formMap.put("bankCard", bankCard);
        formMap.put("authPageCode","bank_info_code");
        if (UserInfoLJ.isUserInformationWrong())
            formMap.put("isInformationWrong", 1);
        toSubScribe(req.saveBankCardInfo(UserInfoLJ.getToken(), ParamsFactoryLJ.getCommonParams(formMap)), new CustomConsumerLJ<BlankResponseLJ>() {
            @Override
            public void call(BlankResponseLJ blankResponse) {
                mvpView.onGetDataNext(blankResponse);
            }
        }, new Consumer<Throwable>() {
            @Override
            public void accept(Throwable throwable) throws Exception {
                mvpView.onGetDataError(throwable);
            }
        });
    }

    public void getPersonInfo() {
        Map<String,Object>map=new HashMap<>();
        map.put("userUuid", UserInfoLJ.getShowUuid());
        toSubScribe(req.getPersonInfo(BuildConfig.channel, UserInfoLJ.getToken(), ParamsFactoryLJ.getCommonParams(map)), new CustomConsumerLJ<PersonalInfoResponseLJ>() {
            @Override
            public void call(PersonalInfoResponseLJ response) {
                mvpView.onGetDataNext(response);
            }
        }, new Consumer<Throwable>() {
            @Override
            public void accept(Throwable throwable) throws Exception {
                mvpView.onGetDataError(throwable);
            }
        });
    }

}
